Ext.onReady(function(){
	Ext.QuickTips.init();

	var login = new Ext.FormPanel({
		labelWidth:80,
		labelAlign:'right',
		title: 'Login',
		url:'users/login',
		border: true,	
		frame: true,
		defaultType:'textfield',
		monitorValid:true,
		width: 270,
		x: 135,
		y: 20,
		items:[
		{
			fieldLabel:'User',
			id: 'data[User][username]',
			name:'data[User][username]',
			allowBlank:false
		},{
			fieldLabel:'Pass',
			id: 'data[User][password]',
			name:'data[User][password]',
			inputType:'password',
			allowBlank:false
		}],

		buttons:[{
			text:'Login',
			formBind: true,
			handler:function(){
				login.getForm().submit(
					{
					method:'POST',
					success:function(form, action) {
						var response=Ext.decode(action.response.responseText);
						if (response.success)
							window.location='/cakex';
							else
							Ext.MessageBox.alert('Status', 'Acesso negado!');	
						},
					failure: function(form, action) {	
						Ext.MessageBox.alert('Status', 'Acesso negado!');
						}
					});
			}
		}]
	});
	
	var win;
	
	if(!win){
        win = new Ext.Window({
            applyTo:'hello-win',
            title: 'CakeX - Autenticação',
            layout:'absolute', 
            width:430,
            height:200,
            closeAction:'hide',
            plain: true,
            items: [{
    			xtype: 'box',
    			width: 100,
    			x: 0, 
    			y: 20,
    			autoEl: { tag: 'div',
    			html: '<div class="app-msg"><img src="images/auth.png" class="app-img" /></div>'
    			}
    		}, login]
        });
    }
    win.show();

});